import {
  getFormMacroListSequence,
  getBasicdataListByType,
  getAdminListRoleByUnitCode,
  getFormGetFieldsOfDeptSelectCtl,
} from '/@/api/formDesign/formDesign';
import { getFormGetFields, getFormGetFieldsOfUser } from '/@/api/flowManage/flowManage';
import { isArray } from '/@/utils/is';
import { usePermissionStoreWithOut } from '/@/store/modules/permission';
import { getLsdList } from '/@/api/process/process';
const permissionStore = usePermissionStoreWithOut();
const currentRoute = permissionStore.getCurrentRoute;
console.log('currentRoute333', currentRoute);
// const { query } = useRoutecurrentRoute.value;

//自动编号 工作流序列号种类选择
export const getFormMacroListSequenceData = async () => {
  let options = await getFormMacroListSequence();
  if (!isArray(options)) {
    options = [];
  }
  return options;
};
//基础数据选择
export const getBasicdataListByTypeData = async (isTree = true) => {
  let options = await getBasicdataListByType({ isTree });
  if (!isArray(options)) {
    options = [];
  }
  return options;
};
//角色中用户选择框 角色选择
export const getAdminListRoleByUnitCodeData = async () => {
  let options = await getAdminListRoleByUnitCode();
  if (!isArray(options)) {
    options = [];
  }
  return options;
};

export const getFormGetFieldsOfUserData = async () => {
  const data = await getFormGetFieldsOfUser({ formCode: currentRoute.query.formCode });
  return data;
};

//用户选择中:联动部门字段接口
export const getFormGetFieldsOfDeptSelectCtlData = async () => {
  if (!currentRoute?.query?.formCode) return [];
  let options = await getFormGetFieldsOfDeptSelectCtl({ formCode: currentRoute.query.formCode });
  if (!isArray(options)) {
    options = [];
  }
  return options;
};

//当前用户:表单字段
export const getFormGetFieldsData = async () => {
  if (!currentRoute?.query?.formCode) return [];
  let options = await getFormGetFields({ formCode: currentRoute.query.formCode });
  if (!isArray(options)) {
    options = [];
  }
  options.forEach((item) => {
    item.label = item.title;
    item.value = item.name;
    delete item.options;
  });
  options.unshift({
    label: '无',
    value: '',
  });
  return options;
};

//图片
export const getLsdListData = async () => {
  const options = await getLsdList();
  let imgeLists: any = [];
  if (!isArray(options)) {
    imgeLists = [];
  } else {
    if (options && options.length > 0) {
      options.forEach((item) => {
        const obj = {};
        obj['value'] = item.id;
        obj['title'] = item.name;
        obj['label'] = item.name;
        obj['disabled'] = true;
        obj['children'] = [];
        if (item.images && item.images.length > 0) {
          obj['children'] = item.images.map((el) => {
            return {
              value: el.path,
              title: el.name,
              label: el.name,
            };
          });
          imgeLists.push(obj);
        }
      });
      console.log('imgeLists', imgeLists);
    }
  }
  return imgeLists;
};

export const attributeList = [
  {
    label: '控件字段',
    type: 'input',
    field: 'name',
    componentProps: {
      placeholder: '必填项',
      require: true,
    },
  },
  {
    label: '控件名称',
    type: 'input',
    field: 'title',
    componentProps: {
      placeholder: '必填项',
      require: true,
    },
  },
  {
    label: '标签名称',
    type: 'input',
    field: 'label',
    componentProps: {
      placeholder: '必填项',
      require: true,
    },
  },
  {
    label: '必填项',
    type: 'switch',
    field: 'canNull',
    componentProps: {
      checkedValue: false,
      unCheckedValue: true,
    },
  },
  {
    label: '数据类型',
    type: 'select',
    field: 'dataType',
    componentProps: {
      placeholder: '请选择',
      allowClear: true,
      options: [
        {
          label: '字符串型',
          value: '0',
        },
        {
          label: '文本型',
          value: '1',
        },
        {
          label: '整型',
          value: '2',
        },
        {
          label: '长整型',
          value: '3',
        },
        {
          label: '布尔型',
          value: '4',
        },
        {
          label: '浮点型',
          value: '5',
        },
        {
          label: '双精度型',
          value: '6',
        },
        {
          label: '日期型',
          value: '7',
        },
        {
          label: '日期时间型',
          value: '8',
        },
        {
          label: '价格型',
          value: '9',
        },
        {
          label: '长文本型',
          value: '10',
        },
      ],
    },
  },
  {
    label: '默认值',
    describe: '默认值以宏控件内置默认的为准，如：基础数据的默认值，如果为空，则使用此处的默认值',
    type: 'textarea',
    field: 'value',
    componentProps: {
      placeholder: '无则不填',
    },
  },
  {
    label: '控件样式宽',
    type: 'EInputSize2',
    field: 'widthUnit',
    componentProps: {
      defaultValue: {
        width: 150,
        unit: 'px',
      },
    },
  },
  {
    label: '长度/大小', //minT minV maxT maxV
    type: 'lenSize',
    field: 'range',
    componentProps: {
      defaultValue: {
        minT: 'd=',
        minV: '',
        maxT: 'x=',
        maxV: 100,
      },
      minTList: [
        {
          label: '>=',
          value: 'd=',
        },
        {
          label: '>',
          value: 'd',
        },
      ],
      // minVList: [
      //   {
      //     label: '当前日期',
      //     value: 'curDate',
      //   },
      // ],
      maxTList: [
        {
          label: '<=',
          value: 'x=',
        },
        {
          label: '<',
          value: 'x',
        },
      ],
      // maxVList: [
      //   {
      //     label: '当前日期',
      //     value: 'curDate',
      //   },
      // ],
    },
  },
  {
    label: '显示',
    type: 'switch',
    field: 'isShow',
    componentProps: {
      defaultValue: true,
      checkedValue: true,
      unCheckedValue: false,
    },
  },
  {
    label: '只读',
    type: 'switch',
    field: 'isReadOnly',
  },
  {
    label: '只读类型',
    describe: '仅编辑引用记录时适用于”嵌套表格2“宏控件选取的记录',
    type: 'select',
    field: 'readOnlyType',
    componentProps: {
      placeholder: '请选择',
      defaultValue: '',
      allowClear: true,
      options: [
        {
          label: '不限',
          value: '',
        },
        {
          label: '仅添加时',
          value: '0',
        },
        {
          label: '仅编辑时',
          value: '1',
        },
        {
          label: '仅编辑引用记录时',
          value: '2',
        },
      ],
    },
  },
  {
    label: '描述',
    type: 'textarea',
    field: 'description',
    labelStyle: 'width:40px',
    componentProps: {
      placeholder: '无则不填',
      style: 'height:150px',
    },
  },
];
export const eventList = [
  {
    type: 'input',
    describe: '输入值',
  },
  {
    type: 'change',
    describe: '值修改',
  },
  {
    type: 'pressEnter',
    describe: '按下回车的回调',
  },
  {
    type: 'focus',
    describe: '获取焦点',
  },
  {
    type: 'blur',
    describe: '失去焦点',
  },
];

export const actionList = [
  {
    type: 'focus',
    describe: '使 input 获取焦点',
  },
  {
    type: 'blur',
    describe: '使 input 失去焦点',
  },
  {
    type: 'select',
    describe: '选中 input 中的文字',
  },
];
